package whf.framework.log.service;

import java.util.List;

import whf.framework.exception.RemoveException;
import whf.framework.exception.ServiceNotFoundException;
import whf.framework.log.dao.AuditHistoryDAO;
import whf.framework.log.dao.AuditHistoryDetailDAO;
import whf.framework.log.entity.AuditHistory;
import whf.framework.log.entity.AuditHistoryDetail;
import whf.framework.util.BeanFactory;

/**
 * @author wanghaifeng
 * @email king@126.com
 * @modify 2008-01-21
 */
public class AuditHistoryServiceImp extends whf.framework.service.ServiceImp<AuditHistory> implements AuditHistoryService {
	private AuditHistoryDetailDAO auditHistoryDetailDAO;
	
	public void setAuditHistoryDAO(AuditHistoryDAO auditHistoryDAO) {
		this.entityDAO = auditHistoryDAO;
	}
	
	public void setAuditHistoryDetailDAO(AuditHistoryDetailDAO auditHistoryDetailDAO) {
		this.auditHistoryDetailDAO = auditHistoryDetailDAO;
	}

	public static AuditHistoryService getAuditHistoryService() throws ServiceNotFoundException {
		return (AuditHistoryService)BeanFactory.getService(AuditHistoryServiceImp.class) ;
	}

	@Override
	public void remove(AuditHistory entity) throws RemoveException {
		try{
			List<AuditHistoryDetail> details = this.auditHistoryDetailDAO.find("t.auditHistory=?", entity);
			for(AuditHistoryDetail detail: details) {
				this.auditHistoryDetailDAO.remove(detail);
			}
		} catch(Exception e) {
			throw new RemoveException(e);
		}
		super.remove(entity);
	}
	
} 